package cmd

import (
	"log"

	"go.uber.org/zap"
	"k8s.io/client-go/dynamic"
	"k8s.io/client-go/kubernetes"
)

// 根据配置对象，初始化一个k8s clientSet
func (c *K8sConfig) InitClient() *kubernetes.Clientset {
	client, err := kubernetes.NewForConfig(c.K8sRestConfig())
	if err != nil {
		NewMyRotaLogger().Info("初始化k8s client 失败", zap.String("msg", err.Error()))
		log.Fatal(err)
	}
	NewMyRotaLogger().Info("初始化k8s client成功", zap.String("msg", ""))
	return client
}

// 根据配置对象，初始化一个k8s dymaincClient
func (c *K8sConfig) InitDynamicClient() dynamic.Interface {
	dynamicClient, err := dynamic.NewForConfig(c.K8sRestConfig())
	if err != nil {
		log.Fatal(err)
	}
	return dynamicClient

}
